package com.example.a22310.myapplication.ViewModel.Post;


import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Beans.PostComment;
import com.example.a22310.myapplication.Listener.PostListener;
import com.example.a22310.myapplication.Model.PostModel;

import java.util.List;

public class PostCommViewModel implements PostListener<PostComment> {
    private ActivityPostDetailBinding binding;
    private AppCompatActivity activity;
    private int postid;
    private int userid;
    private int flag;


    public PostCommViewModel(AppCompatActivity activity, ActivityPostDetailBinding binding,int userid,int postid,int flag){
        this.activity = activity;
        this.binding = binding;
        this.userid = userid;
        this.postid = postid;
        this.flag = flag;
        binding.setPostcomm(this);
        PostModel postModel=new PostModel();
        postModel.postComm(PostCommViewModel.this,userid,postid,flag);
    }

    @Override
    public void onSuccess(PostComment postComment) {

        if(postComment.getCode()!=404){
            List<PostComment.ComListBean> postlistBeen =  postComment.getComList();
            binding.recyclerViewComment.setLayoutManager(new LinearLayoutManager(activity));
            if(postlistBeen ==null){
                binding.recyclerViewComment.setVisibility(View.GONE);
            }else{
                MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_post_comment,
                        postlistBeen, BR.postcomm);
                binding.recyclerViewComment.setAdapter(adapter);
            }

        }

    }


    @Override
    public void onFailure() {
    }




}